rm(list= ls())

library(scales)
library(tidyverse)
library(haven)
library(fixest)
library(janitor)
library(fastDummies)

## Data is available at GESIS: https://search.gesis.org/research_data/ZA6988 

dat <- haven::read_dta('data_private/ZA6988_v1-2-0.dta') %>%
  mutate(anti_mig_abschiebung = ifelse(V194 == 1, 1, 0)) %>%
  mutate(party_pref = case_when(V15 == 1 ~ 'CDU/CSU',
                                V15 == 2 ~ 'SPD',
                                V15 == 4 ~ 'Greens',
                                V15 == 3 ~ 'Left Party',
                                V15 == 5 ~ 'FDP',
                                V15 == 6 ~ 'AfD',
                                TRUE ~ 'other')) %>%
  dplyr::select(contains('anti_mig'), 'party_pref', 'V317', 'V318', 'V7', 'V321') %>%
  rename(age = V318,
         gender = V317,
         educ = V321,
         bland = V7) %>%
  mutate_at(vars(one_of('age', 'gender', 'bland', 'educ')), as.factor)

dat

## 

dat <- fastDummies::dummy_cols(dat, 
                        select_columns = 'party_pref',
                        remove_selected_columns = T) %>%
  clean_names()

## Results Figure A1 in Table Form 

res_all <- feols(c(party_pref_cdu_csu, party_pref_af_d, party_pref_fdp, party_pref_greens, party_pref_left_party, party_pref_spd) ~ anti_mig_abschiebung + age + gender + educ + bland,
            data = dat) 

etable(res_all, keep = 'anti_mig_abschiebung')







